﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.IO.IsolatedStorage;

namespace LiveEduWizard
{
    public class UserSettings
    {
        private static IsolatedStorageSettings userSettings = IsolatedStorageSettings.ApplicationSettings;

        static UserSettings()
        {
            Load();
        }

        private static string liveEduAccount = "live@edu";
        public static string LiveEduAccount
        {
            get
            {
                return liveEduAccount;
            }
            set
            {
                liveEduAccount = value;
                if (userSettings.Contains("LiveEduAccount"))
                {
                    userSettings["LiveEduAccount"] = value;
                }
                else
                {
                    userSettings.Add("LiveEduAccount", value);
                }
            }
        }

        private static string selectedTab = "agenda";
        public static string SelectedTab
        {
            get
            {
                return selectedTab;
            }
            set
            {
                selectedTab = value;
                if (userSettings.Contains("SelectedTab"))
                {
                    userSettings["SelectedTab"] = value;
                }
                else
                {
                    userSettings.Add("SelectedTab", value);
                }
            }
        }

        private static Boolean simultaneousTimetableGridScrolling = true;
        public static Boolean SimultaneousTimetableGridScrolling
        {
            get
            {
                return simultaneousTimetableGridScrolling;
            }
            set
            {
                simultaneousTimetableGridScrolling = value;
                if (userSettings.Contains("SimultaneousTimetableGridScrolling"))
                {
                    userSettings["SimultaneousTimetableGridScrolling"] = value;
                }
                else
                {
                    userSettings.Add("SimultaneousTimetableGridScrolling", value);
                }                
            }
        }

        private static string backgroundColor = "dark";
        public static string BackgroundColor
        {
            get
            {
                return backgroundColor;
            }
            set
            {
                backgroundColor = value;
                if (userSettings.Contains("BackgroundColor"))
                {
                    userSettings["BackgroundColor"] = value;
                }
                else
                {
                    userSettings.Add("BackgroundColor", value);
                }
            }
        }

        private static int accentColorIndex = 0;
        public static int AccentColorIndex
        {
            get
            {
                return accentColorIndex;
            }
            set
            {
                accentColorIndex = value;
                if (userSettings.Contains("AccentColorIndex"))
                {
                    userSettings["AccentColorIndex"] = value;
                }
                else
                {
                    userSettings.Add("AccentColorIndex", value);
                }
            }
        }


        public static void Load()
        {
            if (userSettings.Contains("LiveEduAccount"))
            {
                liveEduAccount = Convert.ToString(userSettings["LiveEduAccount"]);
            }

            if (userSettings.Contains("SelectedTab"))
            {
                selectedTab = Convert.ToString(userSettings["SelectedTab"]);
            }

            if (userSettings.Contains("SimultaneousTimetableGridScrolling"))
            {
                simultaneousTimetableGridScrolling = Convert.ToBoolean(userSettings["SimultaneousTimetableGridScrolling"]);
            }

            if (userSettings.Contains("BackgroundColor"))
            {
                backgroundColor = Convert.ToString(userSettings["BackgroundColor"]);
            }

            if (userSettings.Contains("AccentColorIndex"))
            {
                accentColorIndex = (int) userSettings["AccentColorIndex"];
            }
        }

        public static void Save()
        {
            userSettings.Save();
        }

        public static void Clear()
        {
            userSettings.Clear();
        }
    }
}